/**
 * 键值结构
 * 
 * @author Ho Lee
 * @since 2021/7/13
 */

package xyz.holee.db.KeyValueDatabase;

import java.util.ArrayList;

public class KeyValue {
    public String className;
    public ArrayList<String> key;
    public ArrayList<String> value;

    public KeyValue(String className) {
        this.className = className;
        this.key = new ArrayList<>();
        this.value = new ArrayList<>();
    }
    public void setKeyValue(String keyvalue) {
        String []kv = keyvalue.split("=", 2);
        String k, v;
        if (kv.length < 2) {
            k = kv[0];
            v = "";
        } else {
            k = kv[0];
            v = kv[1];
        }
        this.setKeyValue(k, v);
    }
    public void setKeyValue(String k, String v) {
        int keyIndex = this.key.indexOf(k);
        if (keyIndex > -1) {
            this.value.set(keyIndex, v);
        } else {
            this.key.add(k);
            this.value.add(v);
        }
    }
}
